Test Failed
Pull Request — master (#2)
by Yo
01:40
created

index.js ➔ ???   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 37
rs 8.8571

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ ... ➔ ??? 0 3 1
1
"use strict";
2
3
const config = require('config');
4
const Hapi = require('hapi');
5
const Inert = require('inert');
6
const Vision = require('vision');
7
const HapiSwagger = require('hapi-swagger');
8
const taskLogger = require('../logger/taskLogger')('Server');
9
const pkg = require('../../package.json');
10
const routeList = require('./routes');
11
12
const server = new Hapi.Server();
13
const wrapper = {};
14
let serverStarted = false;
15
16
server.connection({
17
    host: config.server.host,
18
    port: config.server.port
19
});
20
21
22
23
/**
24
 * @returns {Promise<null|Error>}
25
 */
26
wrapper.start = () => {
27
    taskLogger.starting();
28
29
    routeList.forEach(route => {
30
        server.route(route);
31
    });
32
33
    const options = {
34
        'info': {
35
            'title': pkg.name,
36
            'version': pkg.version
37
        }
38
    };
39
40
    return server.register([
41
        Inert,
42
        Vision,
43
        {
44
            'register': HapiSwagger,
45
            'options': options
46
        }]
47
    )
48
        .then(err => server.start())
0 ignored issues
show
Unused Code introduced by
The parameter err is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
49
        .then(() => {
50
            serverStarted = true;
51
            taskLogger.started();
52
            taskLogger.info(`Running at ${server.info.uri}`);
53
        })
54
        .catch(error => {
55
            taskLogger.error('Stopping after an error');
56
            return wrapper.stop()
57
                .then(() => {
58
                    return Promise.reject(error);
59
                })
60
            ;
61
        });
62
};
63
64
/**
65
 * @returns {Promise<null|Error>}
66
 */
67
wrapper.stop = () => {
68
    if (serverStarted === false) {
69
        return Promise.resolve(null);
70
    }
71
    taskLogger.stopping();
72
73
    return server.stop()
74
        .then(() => taskLogger.stopped())
75
        .then(() => null)
76
    ;
77
};
78
79
module.exports = wrapper;
80